import request from '@/utils/request'

export interface AttrValueData {
  id?: number
  valueName: string
  attrId: number | undefined
  isEdit?:boolean
}

export type AttrData = {
  id?: number
  attrName: string
  categoryId: number | string
  categoryLevel: number
  attrValueList: AttrValueData[]
  attrIdValueId?:string
}

// {
//   "attrName": "string",
//   "attrValueList": [
//     {
//       "attrId": 0,
//       "id": 0,
//       "valueName": "string"
//     }
//   ],
//   "categoryId": 0,
//   "categoryLevel": 0,
//   "id": 0
// }

export default {
  // 根据选中的123级分类id获取对应的平台属性列表
  // GET /admin/product/attrInfoList/{category1Id}/{category2Id}/{category3Id}
  // attrInfoList
  getList(category1Id: number, category2Id: number, category3Id: number) {
    return request.get<any, AttrData[]>(
      `/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`
    )
  },

  // DELETE /admin/product/deleteAttr/{attrId}
  // deleteAttr
  delete(attrId: number) {
    return request.delete<any, null>(`/admin/product/deleteAttr/${attrId}`)
  },

  // POST /admin/product/saveAttrInfo
  addOrUpdate(attr: AttrData) {
    return request.post<any, null>('/admin/product/saveAttrInfo', attr)
  },
}
